<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>海报列表</title>
		<link rel="stylesheet" href="/dvmini/res/plugins/layui/css/layui.css">
		<link rel="stylesheet" href="/dvmini/res/css/basic.css">
	</head>
	<style>
		.layui-form-select dl{
			max-height:190px;
		}
	</style>
	<body class="wrap">
		<div class="layui-form">
			<div class="layui-form-item searchbox" style="margin-bottom: 0px;">
				
				<!-- <div class="layui-input-inline producttype" style="width: 140px;">
					<select name="producttype" >
						<option value="">海报名称</option>
					</select>
				</div>
				<div class="layui-input-inline productid" style="width: 140px;">
					<select name="productid">
						<option value="0">海报类别</option>
						<option value="1">项目海报</option>
						<option value="2">销售助手首页</option>
						<option value="3">万小二首页</option>
					</select>
				</div>
				<div class="layui-input-inline" style="width: 140px;">
					<input type="text" class="layui-input" name="keyword" placeholder="关键字" />
				</div>
				<button class="layui-btn" lay-submit lay-filter="querybtn">查询</button>
				<button class="layui-btn layui-btn-primary resetBtn" >重置</button> -->
				<a class="layui-btn layui-btn-warm createBtn" href="#"><i class="layui-icon">&#xe61f;</i> 添加海报</a>
			</div>
		</div>
		
		<table class="layui-table">
			<thead>
				<tr>
					<th style="width:30px;">No</th>
					<th style="min-width: 120px;">海报名称</th>
					<th style="min-width:80px;">海报类别</th>
					<th>海报图片</th>
					<th style="min-width: 80px;">操作</th>
				</tr>
			</thead>
				
			<tbody id="tablelist">
				<!-- <tr>
					<td>1</td>
					<td>海报名称</td>
					<td>海报类别</td>
					<td>海报图片</td>
					<td>
						<a href="#" class="layui-btn layui-btn-mini updataBtn">修改</a>
						<a href="#" class="layui-btn layui-btn-mini deleteBtn">删除</a>
					</td>
				</tr> -->
			</tbody>
		</table>
		<div class="nulldata">暂无数据</div>
		<div id="page"></div>
		
	</body>

	<script src='/dvmini/res/js/jquery.min.js'></script>
	<script src="/dvmini/res/plugins/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/dvmini/res/js/me.js"></script>
	<script>
	layui.use(['form', 'element', 'laydate', 'layer', 'laypage'], function() {
		var form = layui.form(),
			element = layui.element(),
			laydate = layui.laydate,
			layer = layui.layer,
			laypage = layui.laypage;
		var queryObj = {
				page: 1,
			} //查询条件
		//查询
		/*  form.on('submit(querybtn)', function(data){
			 queryObj=data.field;
			 queryObj.page=1;
		      initdata(queryObj);
		      form.render();
		  });
		 $(".resetBtn").on("click",function(){
			$("input[name=keyword]").val("");
			$("select[name=projectid]").val("");
			form.render();
			initdata(queryObjd)
		})  */
		//初始化数据
		initdata(queryObj);
		function initdata(queryObj){
			
			$.post("/dvmini/poster/templetList",queryObj,function(data){
				data=data.data;
				console.log(data)
				  laypage({
					cont: 'page',
					pages: data.totalPages, //总页数
					curr: queryObj.page,
					skip: true,
					jump: function(obj, first) {
						if(!first) {
							queryObj.page = obj.curr
							initdata(queryObj);
						}

					}
				});  
				var str="";
				if(data.rows.length<1){
					$(".nulldata").show();
				}else{
					$(".nulldata").hide();
					for(var i=0;i<data.rows.length;i++){
						str+='<tr data-id='+ data.rows[i].id +'>'
							+'<td>'+ ((data.page - 1) * data.pageSize + i + 1) +'</td>'
							+'<td style="text-align:left;">'+ data.rows[i].name+'</td>'
							+'<td>'+ postertype(data.rows[i].postertype) +'</td>'
							+'<td><div class="logoimg" style="background:url(http://mini.weiyisz.com'+data.rows[i].imgurl+') no-repeat center;-webkit-backgorund-size:contain;backgorund-size:contain;float:none;margin:0 auto;"></div></td>'
							+'<td>'
							+'<a href="#" class="layui-btn layui-btn-mini updataBtn">修改</a>'
							+'<a href="#" class="layui-btn layui-btn-mini deleteBtn">删除</a>'
							+'</td>'
							+'</tr>';
					}
				}
				
				$("#tablelist").html(str);
				toNull_G();
			})
		}
		//添加海报模板
		$(document).on("click", ".createBtn", function() {
				if(parent.tab.exists("添加海报")>0){
					var tabid=parent.tab.getTabId("添加海报");
					parent.tab.deleteTab(tabid);
				}
				parent.tab.tabAdd({
					href: "/dvmini/poster/poster",
					icon: "fa-cubes",
					title: "添加海报" 
				});
			})
				//修改海报模板
		$(document).on("click", ".updataBtn", function() {
			var id=$(this).parents("tr").attr("data-id");
				if(parent.tab.exists("修改海报")>0){
					var tabid=parent.tab.getTabId("修改海报");
					parent.tab.deleteTab(tabid);
				}
				parent.tab.tabAdd({
					href: "/dvmini/poster/poster?id="+id,
					icon: "fa-cubes",
					title: "修改海报" 
				});
			})
		//删除海报模板
		$(document).on("click", ".deleteBtn", function() {
			var id=$(this).parents("tr").attr("data-id");
			layer.confirm('您确定要删除该海报吗？', {
				btn: ['确定', '取消'] //按钮
			}, function(index, layero) {
				$.post( "/dvmini/poster/deletetemplet",{id:id}, function(data) {
					console.log(data)
					if(data.code == 0) {
						top.layer.msg("删除成功");
						queryObj.page=1;
						initdata(queryObj);
						layer.close(index);
					}else{
						top.layer.msg(data.msg);
					}
				})
			}, function(index, layero) {
				layer.close(index);
			});
		});

	})
		function postertype(v){
			if(v!==null&&v!==""){
				switch(v){
					case 1:
					 return "项目海报";
					  break;
					case 2:
						 return "销售助手首页";
					  break;
					case 3:
						 return "万小二首页";
					  break;
				}
			}else{
				return ""
			}
		}
	</script>

</html>